package com.dcrzl.shcz.module.sys.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;

import com.dcrzl.shcz.common.entity.info.Gov;
import com.dcrzl.shcz.common.entity.sys.SysRoleGov;
import com.dcrzl.shcz.common.mapper.sys.SysRoleGovMapper;
import com.dcrzl.shcz.common.service.impl.BaseServiceImpl;
import com.dcrzl.shcz.common.utils.PageInfo;
import com.dcrzl.shcz.common.utils.Result;
import com.dcrzl.shcz.common.utils.SysConstant;
import com.dcrzl.shcz.module.info.service.GovService;
import com.dcrzl.shcz.module.sys.service.SysRoleGovService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;

@Service("sysRoleGovService")
public class SysRoleGovServiceImpl extends BaseServiceImpl<SysRoleGovMapper, SysRoleGov> implements SysRoleGovService {

    private LambdaQueryWrapper<SysRoleGov> commonWrapper(SysRoleGov sysRoleGov) {
        LambdaQueryWrapper<SysRoleGov> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(Objects.nonNull(sysRoleGov.getId()), SysRoleGov::getId, sysRoleGov.getId());
        wrapper.eq(Objects.nonNull(sysRoleGov.getRoleId()),SysRoleGov::getRoleId, sysRoleGov.getRoleId());
        wrapper.eq(Objects.nonNull(sysRoleGov.getGovId()),SysRoleGov::getGovId, sysRoleGov.getGovId());
        return wrapper;
    }


    @Override
    public Result<SysRoleGov> selectOne(SysRoleGov sysRoleGov) {
        LambdaQueryWrapper<SysRoleGov> wrapper = this.commonWrapper(sysRoleGov);
        return super.selectOne(wrapper);
    }

    @Override
    public Result<List<SysRoleGov>> selectList(SysRoleGov sysRoleGov) {
        LambdaQueryWrapper<SysRoleGov> wrapper = this.commonWrapper(sysRoleGov);
        return super.selectList(wrapper);
    }

    @Override
    public PageInfo<SysRoleGov> selectPage(SysRoleGov sysRoleGov) {
        LambdaQueryWrapper<SysRoleGov> wrapper = this.commonWrapper(sysRoleGov);
        return super.selectPage(sysRoleGov, wrapper);
    }



    @Override
    public Result<Integer> removeById(Serializable id) {
        SysRoleGov sysRoleGov = new SysRoleGov().setStatus(SysConstant.DATA_DELETE_STATUS)
                .setId((Long) id);
        return this.updateById(sysRoleGov);
    }

}